package com.tanhua.server.controller;

import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * @auther : 白月尘
 * @date : 16:50  2021/10/20
 */
@RestController
@RequestMapping("/movements")
public class MovementsController {

    @Autowired
    private MovementsService movementsService;


    //动态-发布
    @PostMapping
    public ResponseEntity movements(String textContent, MultipartFile[] imageContents) {
        movementsService.checkFreezeState(UserHolder.getUserId(),textContent,imageContents);
        //movementsService.movements(textContent, imageContents);
        return ResponseEntity.ok(null);
    }

    //我的动态
    @GetMapping("/all")
    public ResponseEntity all(@RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer pagesize,
                              Long userId) {
        PageResult pageResult = movementsService.findByUserId(page, pagesize, userId);
        return ResponseEntity.ok(pageResult);
    }

    @GetMapping
    public ResponseEntity movements(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pageResult = movementsService.findByFriendId(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }

    //推荐动态
    @GetMapping("/recommend")
    public ResponseEntity recommend(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult pageResult = movementsService.recommend(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/{id}")
    public ResponseEntity findById(@PathVariable("id") String id){
        MovementsVo movementsVo=movementsService.findById(id);
        return ResponseEntity.ok(movementsVo);
    }
    @GetMapping("/{id}/like")
    public ResponseEntity like(@PathVariable("id") String id){
        Integer i=movementsService.like(id);
        return ResponseEntity.ok(i);
    }
    @GetMapping("/visitors")
    public ResponseEntity visitors(){
        List<TodayBest> vo=movementsService.visitors();
        return ResponseEntity.ok(vo);
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity dislike(@PathVariable("id") String id){
        Integer i=movementsService.dislike(id);
        return ResponseEntity.ok(i);
    }
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") String id){
        Integer i=movementsService.love(id);
        return ResponseEntity.ok(i);
    }
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") String id){
        Integer i=movementsService.unlove(id);
        return ResponseEntity.ok(i);
    }
}
